﻿' <summary>
' BeeWit IDE Entorno de desarrollo Visual para php.
' BeeWitPHP IDE es el único entorno de desarrollo para PHP 
' de tipo WYSIWYG (What You See Is What You Get). 
' ¡Ahora si!, aproveche la potencia del lenguaje PHP 
' y desarrolle más rápidamente gracias a la programación 
' intuitiva de BeeWit.
' Copyright © 2010 Dewins Murillo Garcia 
' EMAIL: dewinsmg@gmail.com
' EMAIL: dewins@beewitsoft.com
' Este Programa es Software Libre: usted puede redistribuirlo 
' y/o modificarlo bajo los términos de la Licencia Publica General 
' GNU como es publicada por la Fundacion de Software Libre; 
' en la 3ra versión de la licencia.
' Este programa es distribuido con la esperanza de que sea útil, 
' pero SIN GARANTÍA ALGUNA; sin siquiera la garantía implícita 
' de VALOR COMERCIAL o FORMADO PARA UN PROPÓSITO EN PARTICULAR. 
' Vea la Licencia Publica General GNU para mas detalles.
' Usted debe haber recibido una copia de la Licencia Publica General 
' GNU junto con este programa. Si no, vaya a http://www.beewitsoft.com
' o en http://code.google.com/p/ajax-beewit-php-ide/
' </summary>
' <remarks></remarks>

Imports Aga.Controls.Tree

Public Class ctlDebug
    Private _Model As TreeModel
    Private _client As xdc.XDebug.Client

    Public Sub setCallstack(ByVal client As xdc.XDebug.Client)
        Try
            _client = client
            Dim callstack As List(Of xdc.XDebug.StackEntry) = _client.GetCallStack(-1)
            treeView1.Nodes.Clear()
            For Each entry As xdc.XDebug.StackEntry In callstack
                ' Lexikos: Removed "()" before "at" since it doesn't always apply in AHK.
                treeView1.Nodes.Add((entry.location & " at " & entry.fileName & ":") & entry.lineNumber.ToString)
            Next

            If _Model Is Nothing Then
                _Model = New TreeModel()
                treeViewAdv1.Model = _Model
            End If
            RefreshPropertyList()
        Catch ex As Exception
            Control_Console.AddMessages("setCallstack : " & ex.Message, ctlConsole.enumTypeMessages.isNOTIFICATION)
        End Try
    End Sub

    Public Function BuildDebugNode(ByVal p As xdc.XDebug.Property, ByVal Parent As xdc.GUI.DebugNode) As xdc.GUI.DebugNode
        Dim newNode As New xdc.GUI.DebugNode(p)
        If Parent IsNot Nothing AndAlso TypeOf Parent Is xdc.GUI.DebugNode Then
            newNode.Parent = Parent
        End If
        For Each Child As xdc.XDebug.Property In p.ChildProperties
            Dim tmpNode As xdc.GUI.DebugNode = Me.BuildDebugNode(Child, newNode)
        Next
        Return newNode
    End Function

    Public Sub LoadProperty(ByVal client As xdc.XDebug.Client, ByVal p As xdc.XDebug.Property, ByVal Parent As xdc.GUI.DebugNode)
        Try
            _client = client
            If _Model Is Nothing Then
                _Model = New TreeModel()
                treeViewAdv1.Model = _Model
            End If
            Dim newNode As xdc.GUI.DebugNode = Me.BuildDebugNode(p, Parent)
            _Model.Nodes.Add(newNode)
        Catch ex As Exception
            Control_Console.AddMessages("LoadProperty: " & ex.Message, ctlConsole.enumTypeMessages.isNOTIFICATION)
        End Try
    End Sub

    Private Sub treeViewAdv1_Expanding(ByVal sender As Object, ByVal e As Aga.Controls.Tree.TreeViewAdvEventArgs) Handles treeViewAdv1.Expanding
        If _client Is Nothing Then
            Exit Sub
        End If
        If _client.State <> xdc.XDebug.XdebugClientState.Break Then
            Control_Console.AddMessages("This property is no longer available. Close the Property window and try running the script again.", ctlConsole.enumTypeMessages.isNOTIFICATION)
            Return
        End If
        Dim node As xdc.GUI.DebugNode = TryCast(e.Node.Tag, xdc.GUI.DebugNode)
        If node IsNot Nothing AndAlso Not node.[Property].isComplete Then
            Dim p As xdc.XDebug.Property = _client.GetPropertyValue(node.[Property].FullName, 0)
            ' We don't want 'p' itself. It will be a copy of the node that
            '                 * was marked as inComplete. 
            For Each child As xdc.XDebug.Property In p.ChildProperties
                Dim newNode As xdc.GUI.DebugNode = Me.BuildDebugNode(child, node)
                node.Nodes.Add(newNode)
            Next
            node.[Property].isComplete = True
        End If
    End Sub

    Private Sub RefreshPropertyList()
        If _client.State <> xdc.XDebug.XdebugClientState.Break Then
            Control_Console.AddMessages("This property is no longer available. Close the Property window and try running the script again.", ctlConsole.enumTypeMessages.isNOTIFICATION)
            Return
        End If
        Dim Vars(Me.treeViewAdv1.AllNodes.Count - 1) As String
        Dim i As Long = 0
        For Each dNode As Aga.Controls.Tree.TreeNodeAdv In Me.treeViewAdv1.AllNodes
            Vars(i) = dNode.Tag.name
            i += 1
        Next
        _Model = New TreeModel()
        treeViewAdv1.Model = _Model
        For i = 0 To Vars.Length - 1
            Dim p As xdc.XDebug.Property = _client.GetPropertyValue(Vars(i), 0)
            Dim newNode As xdc.GUI.DebugNode
            If p Is Nothing Then
                p = New xdc.XDebug.Property(Vars(i), "not accesible", xdc.XDebug.PropertyType.Scalar, True, Vars(i))
            End If
            newNode = Me.BuildDebugNode(p, Nothing)
            _Model.Nodes.Add(newNode)
        Next
    End Sub

 
End Class
